package com.sumainfor.wx.tenant.controller;

import com.sumainfor.common.util.FieldCheckUtil;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.wx.tenant.feign.MarketFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 功能描述:
 * 省市区
 * @Auther: zhlu
 * @Date: 2019/3/13 11:19
 * @Description:
 */
@RestController
@RequestMapping("/area")
public class AreaController {

    @Autowired
    MarketFeignClient MarketFeignClient;

    /**
     * 功能描述:
     * 获取所有的省份
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/3/13 11:07
     */
    @GetMapping("/getProvinceList")
    public JsonResult getProvinceList(@RequestParam Map<String,Object> params){
        JsonResult result=new JsonResult();
        params.put("delfg",0);
        result.put(MarketFeignClient.getProvinceList(params).getResult());
        return result;
    }

    /**
     * 功能描述:
     * 根据省编号获取市列表
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/3/13 11:10
     */
    @GetMapping("/getCityList")
    public JsonResult getCityList(@RequestParam Map<String,Object>params){
        JsonResult result=new JsonResult();
        params.put("delfg",0);
        if(!FieldCheckUtil.isMapFieldNotNull(params,new String[]{"ProvinceID"})){
            result.putFailed("ProvinceID不能为空！");
            return  result;
        }
        result.put(MarketFeignClient.getCityList(params).getResult());
        return result;
    }

    /**
     * 功能描述:
     * 根据市编号获取区列表
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/3/11 18:02
     */
    @GetMapping("/getDistrictList")
    public JsonResult getDistrictList(@RequestParam Map<String,Object> params){
        JsonResult result=new JsonResult();
        params.put("delfg",0);
        if(!FieldCheckUtil.isMapFieldNotNull(params,new String[]{"CityID"})){
            result.putFailed("CityID不能为空！");
            return  result;
        }
        result.put(MarketFeignClient.getDistrictList(params).getResult());
        return result;
    }

    /**
     * 功能描述:
     * 根据区编号获取街道列表
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/3/11 18:02
     */
    @GetMapping("/getStreetList")
    public JsonResult getStreetList(@RequestParam Map<String,Object> params){
        JsonResult result=new JsonResult();
        params.put("delfg",0);
        if(!FieldCheckUtil.isMapFieldNotNull(params,new String[]{"DistrictID"})){
            result.putFailed("DistrictID不能为空！");
            return  result;
        }
        result.put(MarketFeignClient.getStreetList(params).getResult());
        return result;
    }

}
